package com.easyhome.dw.timed.task.center.executor;

import com.easyhome.dw.timed.task.center.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author yangpeng
 */
@Slf4j
@Aspect
@Component
public class XxlDestroyConfig {
    private XxlJobSpringExecutor executor;

    @Pointcut("execution(public void com.alibaba.cloud.nacos.registry.NacosServiceRegistry.deregister(..))")
    public void preDestroy() {
    }

    @After("preDestroy()")
    public void afterNacosDeregister() {
        log.info("================== afterNacosDeregister start XxlJob =================");
        if (Objects.isNull(executor)) {
            log.info("================== afterNacosDeregister end XxlJob nullExecutor =================");
        } else {
            executor.destroy();
            log.info("================== afterNacosDeregister end XxlJob =================");
        }
    }

    public void setExecutor(XxlJobSpringExecutor executor) {
        this.executor = executor;
        log.info("================== afterNacosDeregister registry XxlJob =================");
    }
}